#include "pub_pop_delay.h"
#include "ui_pub_pop_delay.h"
#include <QMessageBox>
#include <QtDebug>
#include <QSqlQueryModel>
#include <QModelIndex>
#include "pub_var.h"
#include <QThread>
#include <QKeyEvent>

Pub_pop_delay::Pub_pop_delay(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Pub_pop_delay)
{
    ui->setupUi(this);

    this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());

    connect(&tm, &QTimer::timeout, this, &Pub_pop_delay::tmot);

    retValue = "";
    //tm.start(330);
    ui->pgbM->setMaximum(99);
    ui->label->setText("");
    //QWidget::installEventFilter(this);//为这个窗口安装过滤器
    needClose = false;
}

Pub_pop_delay::~Pub_pop_delay()
{
    delete ui;
}

void Pub_pop_delay::closeEvent(QCloseEvent *event)
{
    if(!needClose)
    {
        event->ignore();
        qDebug()<<"received a event but ignore.";
    }

}

void Pub_pop_delay::closeWindow()
{
    close();
    tm.stop();
}
void Pub_pop_delay::setText(QString s)
{
    ui->label->setText(s);
    tm.start(330);
    qApp->processEvents();
}

void Pub_pop_delay::setNeedClose(bool status)
{
    needClose = status;
}

void Pub_pop_delay::tmot()
{
    int curV = ui->pgbM->value();
    curV += 9;
    if(curV > ui->pgbM->maximum())
    {
        curV = 0;
    }
    ui->pgbM->setValue(curV);
    qApp->processEvents();
}
